<template>
  <div>
    <el-form
      ref="searchForm"
      class="searchForm"
      :model="searchForm"
      label-width="50"
    >
      <el-row :gutter="12">
        <!--        合计24份  -->
        <el-col :span="6">
          <el-form-item prop="queryCondition.bookName" label="书籍名称">
            <el-input v-model.trim="searchForm.queryCondition.bookName">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.author" label="作者">
            <el-input v-model="searchForm.queryCondition.author"> </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.bookPrice" label="书籍价格">
            <el-input v-model="searchForm.queryCondition.bookPrice"> </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.publisher" label="出版社">
            <el-input v-model="searchForm.queryCondition.publisher"> </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-edit"
          @click="queryByCondition(1)"
          >查询</el-button
        >
        <el-button
          type="warning"
          icon="el-icon-remove"
          @click="() => $refs.searchForm.resetFields()"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table :data="results" class="resultsTable" stripe>
      <el-table-column prop="bookName" label="书名"></el-table-column>
      <el-table-column prop="author" label="作者"></el-table-column>
      <el-table-column prop="bookPrice" label="书籍价格"></el-table-column>
      <el-table-column prop="publisher" label="出版社"></el-table-column>

      <!--          <el-table-column prop="" label="" :formatter="Format">-->
      <!--          </el-table-column>-->
      <el-table-column width="180px" fixed="left">
        <template slot-scope="props">
          <el-button
            class="el-button--mini"
            type="warning"
            icon="el-icon-edit"
            @click="openById(props.row.bookName)"
            >编辑</el-button
          >
          <el-button
            class="el-button--mini"
            type="danger"
            icon="el-icon-edit"
            @click="delete props.row.bookName"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// import New from './components/New.vue';
export default {
  name: "Book",
  components: {
    // New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  // "pageNum": 1,
  // "pageSize": 6,
  // "queryCondition": {
  //   "author": "唐朔飞",
  //   "bookName": "",
  //   "bookPrice": 0,
  //   "publisher": ""
  // }

  data() {
    return {
      sampleD: "value",
      searchForm: {
        pageNum: 1,
        pageSize: 6,
        queryCondition: {
          bookName: null,
          author: null,
          bookPrice: null,
          publisher: null,
        },
      },
      total: 10,
      results: [],
    };
  },
  computed: {
    // sampleC() {
    //     return this.sampleD+'--';
    // }
  },
  created() {},
  mounted() {},
  methods: {
    sampleM() {},
    queryByCondition(pageNum) {
      if (pageNum) this.searchForm.pageNum = pageNum;
      this.$message.success(JSON.stringify(this.searchForm));
      this.$http({
        method: "post",
        url: "/ceto//book/query",
        data: this.searchForm,
      }).then(
        (res) => {
          this.total = res.data.total;
          this.results = res.data.results;
        },
        (error) => {
          this.$message.warning("query mistake：" + error.response.status);
        }
      );
    },
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<!--<style scoped>-->
<style lang="scss" scoped></style>
